package com.jt.controller;

import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/selectAll")
    public List<User> selectAll(){
       return userService.selectAll();
    }

    @DeleteMapping("/deleteOne/{id}")
    public String deleteOne(@PathVariable Integer id){
        userService.deleteOne(id);
        return "删除成功!";
    }
    @PostMapping("/insertOne")
    public String insertOne(@RequestBody User user){
        userService.insertOne(user);
        return "添加用户成功!";
    }
    @PutMapping("updateOne")
    public String updateOne(@RequestBody User user){
        userService.updateOne(user);
        return "数据更新成功!";
    }
}